package com.ccn.crm.util;

import com.ccn.crm.util.HttpUtil;
import com.alibaba.fastjson.JSON;

import java.util.HashMap;
import java.util.Map;

/**
 * 获取企业token
 */
public class GetToken {

    public static Map<String, Object> getToken() {
//        List<NameValuePair> params=new ArrayList<NameValuePair>();
//        params.add(new BasicNameValuePair("appId","FSAID_1317bb2"));
//        params.add(new BasicNameValuePair("appSecret","7920b0aebf4044e89f7df0530beb03d4"));
//        params.add(new BasicNameValuePair("permanentCode","90336CD9EBAD8C3F387E70B03D707EF4"));
        //获取token路径
        String url = "https://open.fxiaoke.com/cgi/corpAccessToken/get/V2";
        Map<String, Object> jsonObject = new HashMap<String, Object>();
        //设置访问参数
        jsonObject.put("appId","FSAID_1317bb2");
        jsonObject.put("appSecret","7920b0aebf4044e89f7df0530beb03d4");
        jsonObject.put("permanentCode","90336CD9EBAD8C3F387E70B03D707EF4");
        //把参数转化为字符串
        String json = JSON.toJSONString(jsonObject);
        //调用工具进行跨域请求获取token的corpID等参数
        String post = HttpUtil.httpProxy(url, json, "post", "application/json");
        //  String str="{\"corpAccessToken\":\"7129AE8DA6F9C5188C40BA920118A0E2\",\"corpId\":\"FSCID_A6D390D2E5FFF878491C1F5E6DA2994B\",\"expiresIn\":2422,\"errorCode\":0,\"errorMessage\":\"success\"}\n";
        //将获取的参数转化成map类型
        HashMap token = JSON.parseObject(post, HashMap.class);
        //设值，userOpenID
        token.put("currentOpenUserId","FSUID_3A1374846D218AFA854F470DFAA8B3FB");
//        String corpAccessToken = (String)token.get("corpAccessToken");
//        System.out.println(corpAccessToken);
//        String corpId = (String)token.get("corpId");
//        System.out.println(corpId);
//        String currentOpenUserId = (String)token.get("currentOpenUserId");
//        System.out.println(currentOpenUserId);
        //String currentOpenUserId="FSUID_3A1374846D218AFA854F470DFAA8B3FB";
//        System.out.println("打印");
        return token;

    }

}
